﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SalesSys.DAL.Models;
using SalesSys.Comm.BLL;

namespace SalesSys.BLL.Sales
{
    public interface IOrderBLL : IBaseBLL<Order, Guid>
    {
        /// <summary>
        /// 设置指定订单状态
        /// </summary>
        /// <param name="createrId"></param>
        /// <param name="orderId"></param>
        /// <param name="orderState"></param>
        /// <remarks>
        /// 记录变化到订单历史
        /// </remarks>
        void SetState(Guid createrId, Guid orderId, OrderState orderState);
        /// <summary>
        /// 结算
        /// </summary>
        /// <param name="order"></param>
        /// <remarks>
        /// 重新计算订单金额
        /// 设置货款、运费
        /// 比较货款、运费，与实际支付差额
        /// 对差额进行入账
        /// 设置订单状态：已结算
        /// </remarks>
        void Settlement(Order order, Employee emp);
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="empId"></param>
        /// <remarks>
        /// 取消订单
        /// 记录到订单记录
        /// </remarks>
        void Cancel(Guid orderId, Guid empId);
        /// <summary>
        /// 直发采购单单创建
        /// </summary>
        /// <param name="order"></param>
        /// <remarks>
        /// 检查订单类型与供应商是否相符
        /// 设置订单信息
        /// 通过账户判断是否非标
        /// 判断商品是否归属供应商
        /// 计算商品价格：优惠、非标
        /// 计算总价、
        /// 设置运费户头，计算运费
        /// A.判断是否需要议价，提交审批流程，记录日志
        /// A.是否需要锁价，提交审批流程，记录日志
        /// A.无需审批，等待支付，信用客户处理，记录日志
        /// </remarks>
        void DirectCreate(Order orderDto);
        /// <summary>
        /// 商品锁价单创建
        /// </summary>
        /// <param name="order"></param>
        ///<remarks>
        /// 获取对应锁价单
        /// 检查商品信息是否与锁价相同
        /// 计算金额
        /// 检查锁价单金额
        /// 扣除锁价单金额，计入已支付
        /// 记录日志
        /// </remarks>
        void ProductLockCreate(Order order);
        /// <summary>
        /// 基价锁价创建
        /// </summary>
        /// <param name="order"></param>
        ///<remarks>
        /// 获取对应锁价单
        /// 检查商品信息是否与锁价相同
        /// 计算金额
        /// 检查锁价单金额
        /// 扣除锁价单金额，计入已支付
        /// 记录日志
        /// </remarks>
        void BasePriceLockCreate(Order order);
        /// <summary>
        /// 自采直销
        /// </summary>
        /// <param name="order"></param>
        /// <remarks>
        /// 
        /// </remarks>
        void FreedomCreate(Order order);
        /// <summary>
        /// 库提销售
        /// </summary>
        /// <param name="order"></param>
        void DepotCreate(Order order);
        /// <summary>
        /// 对一个订单创建出库单
        /// </summary>
        /// <param name="order"></param>
        void ToDepotDelivery(Order order, Guid empId);

        /// <summary>
        /// 修改商品信息
        /// </summary>
        /// <param name="orderDto"></param>
        /// <param name="emp"></param>
        void CommodityInfoEdit(Order orderDto, IEmployee emp);

        /// <summary>
        /// 支付差额
        /// </summary>
        /// <param name="orderDto"></param>
        /// <param name="emp"></param>
        bool PayAdvanCharge(Guid orderId);

        /// <summary>
        /// 根据关键字和状态查计划单
        /// </summary>
        /// <param name="searchKey">模糊查询</param>
        /// <param name="state">状态</param>
        /// <param name="qinfo">翻页属性</param>
        /// <returns></returns>
        KeyValuePair<int, IEnumerable<Order>> Select(string searchKey, OrderState? state, QueryInfo qinfo);

        /// <summary>
        /// 根据关键字和状态查计划单
        /// </summary>
        /// <param name="searchKey">模糊查询</param>
        /// <param name="state">状态</param>
        /// <param name="page">页码</param>
        /// <param name="rows">每页数量</param>
        /// <returns></returns>
        KeyValuePair<int, IEnumerable<Order>> Select(string searchKey, OrderState? state, Guid? customerId = null, DateTime? startTime=null, DateTime? endTime=null, int page = 1, int rows = 10);
       
        /// <summary>
        /// 应收账款
        /// </summary>
        /// <returns></returns>
        object[][] Receivable();

          /// <summary>
        /// 根据类型查询订单
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="state"></param>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        Tuple<int, Order[]> OrderList(string keys = null, Guid? empId = null, OrderType? orderType = null, OrderState? state = null, DateTime? startTime=null, DateTime? endTime=null,int page = 1, int rows = 10);


        /// <summary>
        /// 订单总量
        /// </summary>
        /// <returns></returns>
        string[][] SelectVolumeTotal(DateTime begin, DateTime end);
    }
}
